import Taro , { Component } from '@tarojs/taro';
import { View, Text , WebView} from '@tarojs/components';
import app from '../../main';

export default class WebViewContaziner extends Component {

   config = {
       navigationBarTitleText: ''
  }

  state={
    webUrl:'',
    token:''
  }

  handleMessage(e){
    let data = e.detail 
    console.log("特定时机参数",data)
  }
  handleLoad(e){
    console.log("成功加载",e);
  }
  handleError(e){
    console.log("失败",e)
  }

  componentWillMount () {
    let url = encodeURI(this.$router.params.webUrl)
    console.log("url",url)
    console.log("url",typeof url)
    let group  = this.$router.params.group
    console.log("grooup",group)
    console.log("grooup",typeof group)
    if(this.$router.params.webUrl){
      this.setState({
        webUrl:url
      })
      console.log(this.$router.params.webUrl)
      console.log("加载了容器")
    }else{
      if(this.$router.params.group){
        // let hop_url = `${app.apiUri}/chat.html?group=${group}&grader=2`;
        let hop_url = this.$router.params.group
        this.setState({
          webUrl:hop_url
        })
        console.log("外部链接")
      }
    }

   console.log(this.$router.params.token)
   console.log(app.getToken())
  }

  render() {
   
    
    return (
      <View>
        {
          this.state.webUrl.indexOf('getCoupons') == -1
          ?
          <WebView src={this.state.webUrl}
          onMessage={this.handleMessage.bind(this)}
          onLoad={this.handleLoad.bind(this)}
          onError={this.handleError.bind(this)}
          ></WebView>
          
          :
          
          <WebView src={this.state.webUrl +'?token='+ app.getToken()}
          onMessage={this.handleMessage.bind(this)}
          onLoad={this.handleLoad.bind(this)}
          onError={this.handleError.bind(this)}
          ></WebView>
        }
       
      </View>
    );
  }
}